#include<bits/stdc++.h>

#define int long long
using namespace std;

signed main()
{
    int n,m;
    cin >> n >> m;
    vector<int>arr(n + 10);
    vector<int>brr(m + 10);
    for(int i = 1; i <= n; i ++) cin >> arr[i];
    for(int i = 1; i <= m; i ++) cin >> brr[i];

    int i = 1;
    int j = 1;
    int ans = 0;
    while(1 <= n && j <= m)
    {
        if(arr[i] == brr[j]) 
        {
            i ++;
            j ++;
            continue;
        } 
        else if(arr[i] < brr[j])
        {
            arr[i + 1] += arr[i];
            i ++;
            ans++; 
        }
        else
        {
            brr[j + 1] += brr[j];
            j++;
            ans++;
        }
    }
    cout << ans << endl;
}
